package cn.itsource.controller;

import cn.itsource.pojo.Logistic;
import cn.itsource.pojo.Order;
import cn.itsource.service.ILogisticService;
import cn.itsource.util.AjaxResult;
import cn.itsource.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/logistic")
public class LogisticController {

    @Autowired
    private ILogisticService logisticService;

    @GetMapping("/{id}")
    public Logistic queryById(@PathVariable Integer id){
        return logisticService.queryById(id);
    }

    @GetMapping("/orderid/{oid}")
    public Logistic queryBySn(@PathVariable Integer oid){
        return logisticService.queryByOrderId(oid);
    }

    @PutMapping
    public AjaxResult saveOrUpdate(@RequestBody Logistic logistic){
        try {
            if(logistic.getId() == null){
                logisticService.add(logistic);
            }else {
                logisticService.update(logistic);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("操作失败");
        }
    }
}
